// pages/主页/主页.js
Page({
  data: {
    label_selected: 0,
    list: [[], [], []],
    whether_load: 1
  },
  onLoad(){
    const that = this
    const app = getApp()
    wx.request({
      url: app.globalData.root_url + 'get_projects/',
      method: 'GET',
      success(res) {
        that.setData({
          list: res.data
        })
      }
    })
    that.setData({
      whether_load: 0
    })
  },

  onShow() {
    if (this.data.whether_load === 1) {
      this.onload()
    }
  },

  //下拉刷新
  onPullDownRefresh(event){
    this.onLoad()
    wx.stopPullDownRefresh()
  },

  // 页面顶部标签切换
  志愿者招募(){
    this.setData({
      label_selected: 0
    })
  },
  学术支持(){
    this.setData({
      label_selected: 1
    })
  },
  其他(){
    this.setData({
      label_selected: 2
    })
  },

  // 创建新项目
  create_new_project(){
    const app = getApp()
    if (app.globalData.login.show == false) {
      wx.showModal({
        content: '请先登录',
        showCancel: false
      })
    } else if (app.globalData.basic_info.name === '' || app.globalData.basic_info.academy === '' || app.globalData.basic_info.licence_number === '' || app.globalData.basic_info.contact_information === '') {
      wx.showModal({
        content: '请填写完整基本信息',
        showCancel: false
      })
    } else {
        wx.navigateTo({
          url: '/pages/新建项目/新建项目',
        })
    }
  },

  项目内容(event){
    wx.navigateTo({
      url: '/pages/项目内容/项目内容?project_id=' + event.currentTarget.dataset.content
    })
  }
})